package ControlLayer;
import ModelLayer.*;
import java.util.*;


/**
 * Write a description of class CustomerCtrl here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CustomerCtrl
{
    // instance variables - replace the example below with your own
    private static CustomerContainer customerContainer = new CustomerContainer();
    private LeaseCtrl leaseCtrl = new LeaseCtrl();

    public CustomerCtrl()
    {
        
    }
    
    public void ifCustomerHasLeases(long _id)
    {
        int n = 0;
        for(Lease lease:leaseCtrl.listAllLeases())
        {
            if(lease.getCustomer().getId() == _id)
            {
                System.out.println(" Customer's Lease ID: " + lease.getId() + "  Item name: " + lease.getRentItem().getName());
                if(lease.getStatus() == true)
                {
                    System.out.println("          Status: PENDING");
                }
                else
                {
                    System.out.println("          Status: ENDED");
                }
                n++;
            }
        }
        
        if(n == 0)
        {
            System.out.println(" This Customer has no Leases yet.");
        }
    }
    
    public Customer getCustomer(long _id)
    {
        for(Customer _customer: customerContainer.getCustomers())
        {
            if(_id == _customer.getId())
            {
                return _customer;
            }
        }
        return null;
    }
    
    public void createCustomer(Customer _customer)
    {
        if(getCustomer(_customer.getId()) == null)
        {
            customerContainer.addCustomer(_customer);
        }
    }
    
    public void removeCustomer(long _id)
    {
            customerContainer.removeCustomer(_id);
    }
    
    public ArrayList<Customer> listAllCustomers()
    {
        return customerContainer.getCustomers();
    }
    
    public void updateCustomer(Customer _customer)
    {
        for(Customer _tofind: customerContainer.getCustomers())
        {
            if(_customer.getId() == _tofind.getId())
            {
                _tofind.setFirstName(_customer.getFirstName());
                _tofind.setLastName(_customer.getLastName());
                _tofind.setBankAccount(_customer.getBankAccount());
                _tofind.setEmail(_customer.getEmail());
                _tofind.setPhone(_customer.getPhone());
                _tofind.setAddress(_customer.getAddress());
                _tofind.setCity(_customer.getCity());
            }
        }
    }
}
